const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Device = sequelize.define('Device', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '设备名称'
  },
  deviceId: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
    comment: '设备ID'
  },
  type: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '设备类型'
  },
  status: {
    type: DataTypes.ENUM('online', 'offline', 'maintenance'),
    defaultValue: 'offline',
    comment: '设备状态'
  },
  location: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '设备位置'
  },
  lastOnlineAt: {
    type: DataTypes.DATE,
    comment: '最后在线时间'
  },
  config: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '设备配置'
  },
  firmware: {
    type: DataTypes.STRING,
    comment: '设备固件版本'
  },
  metadata: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '元数据'
  }
}, {
  comment: '设备信息表'
});

module.exports = Device; 